<?php

namespace apiend\modules\user\models;

use Yii;
use common\helpers\Url;
use common\logics\PositionLogic;
use common\models\spread\SpreadActivity;
use common\logics\ShareLogic;
use common\logics\MapFenceLogic;
use common\models\user\UserMeta;

/**
 * 我的推荐面板
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class UserCenterLogic extends \apiend\models\searchs\DashboardSearch {

    /**
     * @var array 经验等级关注啥的
     */
    public $stats = null;

    /**
     * @var array 认证信息
     */
    public $authent = null;

    /**
     * @var array 任务
     */
    public $task = null;

    /**
     * @var array 双面板
     */
    public $doublesides = [];

    /**
     * @var array 通知栏
     */
    public $notices = [];

    /**
     * @var array 会员服务
     */
    public $services = [];

    /**
     * @var array 会员活动
     */
    public $activitys = [];

    /**
     * @var array 分享内容
     */
    public $share_data = null;

    /**
     * 轮播图
     * @inheritdoc
     */
    protected function setAuthent() {
        $uid = Yii::$app->user->id;
        if ($uid) {
            $user = UserMeta::findOne($uid);
            if ($user) {
                return $user->authent;
            }
        }
        return null;
    }

    /**
     * 轮播图
     * @inheritdoc
     */
    protected function setStats() {
        $data = [
            'follows' => 0,
            'fans' => 0,
            'gold' => 0,
            'credit' => 0,
            'experience' => 0,
            'likes' => 0,
        ];
        $uid = Yii::$app->user->id;
        if ($uid) {
            $user = UserMeta::findOne($uid);
            if ($user) {
                $data = $user->getAccount();
            }
        }
        return $data;
    }

    /**
     * 轮播图
     * @inheritdoc
     */
    protected function setTask() {
        return [
            'text' => '任务中心',
            'link' => Url::h5('test/router'),
            'weblink' => Url::weblink('task')
        ];
    }

    /**
     * 双面板
     * @inheritdoc
     */
    protected function setDoublesides() {
        return PositionLogic::findByName('ucenter.double');
    }

    /**
     * 通知栏
     * @inheritdoc
     */
    protected function setNotices() {
        return PositionLogic::findByName('ucenter.notice');
    }

    /**
     * 会员活动
     * @inheritdoc
     */
    protected function setServices() {
        return MapFenceLogic::findAllByScope('ucenter.service');
    }

    /**
     * 会员活动
     * @inheritdoc
     */
    protected function setActivitys() {
        return SpreadActivity::recommend(3);
    }

    /**
     * APP应用分享信息
     * @inheritdoc
     */
    protected function setShareData() {
        $uid = $this->getPierces('uid', 0);
        return ShareLogic::base($uid);
    }

}
